package com.gopay.common.cps.dao.gsrt.impl;


import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.gsrt.GsrtFailureBidsMasterDao;
import com.gopay.common.domain.gsrt.GsrtFailureBidsMaster;
import com.gopay.common.util.DateUtils;

@Repository("gsrtFailureBidsMasterDao")
public class GsrtFailureBidsMasterDaoImpl extends BaseDAOImpl<GsrtFailureBidsMaster, Serializable>
	implements GsrtFailureBidsMasterDao {
	
	@Override
	public GsrtFailureBidsMaster save(GsrtFailureBidsMaster gsrtFailureBidsMaster){
		//SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
		gsrtFailureBidsMaster.setGopayOrderId(this.getNextId());
		return super.save(gsrtFailureBidsMaster);
	}
	
	//生成国付宝订单号，与cps主订单表共用一个序列
	private String getNextId() {
        String orderId = super.getNextId("ORDER_ID_SEQ");
        orderId = StringUtils.leftPad(orderId, 8, "0");
        orderId = DateUtils.now2string("yyyyMMdd") + orderId;
        return orderId;
    }

	@Override
	public List<GsrtFailureBidsMaster> getByMerIdOrderId(String merId, String orderId) {
		String hql = "from GsrtFailureBidsMaster where  merCustId=:merCustId and merOrderId=:merOrderId ";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("merCustId", merId);
		param.put("merOrderId", orderId);
		List<GsrtFailureBidsMaster> list = this.findByHql(hql, param);
		return list;
	}
	
	
	
}
